package ui;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import Work.Jdbc;

/*查询选项四个查询按钮*/
public class LibrarianSearchButtons extends JFrame implements ActionListener {
	private JButton searchall;
	private JButton searchid;
	private JButton searchl_name;
	private JButton searchnumber;
	private JButton returnbutton;
	// 创建数据库连接类对象

	Jdbc db = new Jdbc();

	public LibrarianSearchButtons() {
		JFrame jFrame = new JFrame("管理员查询功能选择");
		jFrame.setLayout(new BorderLayout());
		JPanel jp1 = new JPanel(new GridLayout(2, 2, 10, 10));// 设置新面板
		// 网格布局GridLayout(int rows, int columns, int hgap, int vgap)行数，列数，组件水平间距，垂直间距
		jp1.setBorder(BorderFactory.createTitledBorder("管理员查询"));
		// this.setLayout(new FlowLayout());
		setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);

		setTitle("管理员查询系统");
		setSize(300, 200);
		setLocationRelativeTo(null);

		// 监听右上角的退出按钮
		this.addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent windowEvent) {
				System.exit(0);
			}
		});
		searchall = new JButton("查询全部管理员");
		searchid = new JButton("按管理员编号查询");
		searchl_name = new JButton("按管理员姓名查询");
		searchnumber = new JButton("按电话查询");

		jp1.add(searchall);
		jp1.add(searchid);
		jp1.add(searchl_name);
		jp1.add(searchnumber);
		getContentPane().add(jp1, BorderLayout.CENTER);
		JPanel jp2 = new JPanel();
		returnbutton = new JButton("返回");
		returnbutton.addActionListener(this);
		jp2.add(returnbutton);
		add(jp2, BorderLayout.SOUTH);

		searchall.addActionListener(this);
		searchid.addActionListener(this);
		searchl_name.addActionListener(this);
		searchnumber.addActionListener(this);

		this.setVisible(true);

	}

	@Override
	public void actionPerformed(ActionEvent e) {
		LibrarianSearch1 LibrarianSearch1 = new LibrarianSearch1();
		if (e.getSource() == searchall) {
			this.dispose();
			LibrarianSearch1.SearchAll(db);
		} else if (e.getSource() == searchl_name) {
			this.dispose();
			LibrarianSearch1.Searchl_namebutton();
		} else if (e.getSource() == searchid) {
			this.dispose();
			LibrarianSearch1.Searchl_idbutton();
		} else if (e.getSource() == searchnumber) {
			this.dispose();
			LibrarianSearch1.Searchl_numberbutton();
		} else if (e.getSource() == returnbutton) {
			this.dispose();
			new LibrarianOp();
		}
	}
}
